﻿using BaiTu.CachingEntity;
using BaiTu.CachingServices.Configuration;
using BaiTu.ICachingServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BaiTu.CachingServices.Coordinator.Wrappers
{
    public class CacheServerWrapper : ICacheProvider
    {

        ICacheProvider cacheProvider = null;
        private CacheServerInfo configInfo;
        public CacheServerWrapper(CacheServerInfo configInfo)
        {
            this.configInfo = configInfo;
            ICacheProvider tmpExecutor = null;
            switch (this.configInfo.ServerType)
            {
                case CacheServerType.Memcache:
                   // tmpExecutor = new CacheProvider.MemcachedCacheProvider(configInfo);
                    break;
                case CacheServerType.Redis:
                    tmpExecutor = new CacheProvider.RedisCacheProvider(configInfo);
                    break;
            }
            cacheProvider = tmpExecutor;
        }
        /// <summary>
        /// 完整的服务器地址
        /// </summary>
        public string FullServerAddress
        {
            get
            {
                return this.configInfo.FullServerAddress;
            }
        }

        public void Put(string key, object value, CacheExpireType expireType, double increment)
        {
            cacheProvider.Put(key, value, expireType, increment);
        }

        public object Get(string key)
        {
            return cacheProvider.Get(key);
        }

        public void Remove(string key)
        {
            cacheProvider.Remove(key);
        }
    }
}
